import { message,Form, Input, Button, Checkbox } from 'antd';
import 'antd/dist/antd.css'
import userApi from '../api/user/user'
function Login(props){
   
   // console.log(props);

     const onFinish = async (values) => {
        
        let result = await userApi.login(values.username,values.password);
          //console.log(result);
          if(result.data.code==1){
            message.success(result.data.msg);
            props.history.push("/main");

          }else{
            
              message.error(result.data.msg);
            };
          
        };

     const onFinishFailed = (errorInfo) => {
          console.log('Failed:', errorInfo);
          
        };
        return (
           <div style={{
               width:"600px",
                height:"300px",
                margin:"100px auto"    
           }}>
            <Form
              name="basic"
              labelCol={{ span: 8 }}
              wrapperCol={{ span: 16 }}
              initialValues={{ remember: true }}
              onFinish={onFinish}
              onFinishFailed={onFinishFailed}
              autoComplete="off"
            >
              <Form.Item
                label="用户名"
                name="username"
                rules={[{ required: true, message: '请输入姓名' }]}
              >
                <Input />
              </Form.Item>
        
              <Form.Item
                label="密码"
                name="password"
                rules={[{ required: true, message: '请输入密码' }]}
              >
                <Input.Password />
              </Form.Item>
              <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                <Button type="primary" htmlType="submit">
                  登录
                </Button>
              </Form.Item>
            </Form>
         </div> 
          );


}

export default Login;